import { _decorator, Component, Node, tween } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Jump')
export class Jump extends Component {
    
    /**
     * 新手学习官方示例教程《摘星星》 2，教程使用的cocos版本是Cocos Creator 2.4.0。有一段代码如下：
    // 跳跃上升
    var jumpUp = cc.tween().by(this.jumpDuration, {y: this.jumpHeight}, { easing: ‘sineOut’ });
    // 下落
    var jumpDown = cc.tween().by(this.jumpDuration, {y: -this.jumpHeight}, { easing: ‘sineIn’ });

    我想改把上面两行代码改成使用Cocos Creator 3.x 版本的API，代码如下：
    //跳跃上升
    let jumpUp = tween().by(this.jumpDuration, {position: new Vec3(0, this.jumpHeight, 0)}, {easing: ‘sineOut’});
    //下落
    let jumpDown = tween().by(this.jumpDuration, {position: new Vec3(0, -this.jumpHeight, 0)}, {easing: ‘sineIn’});
    但是不能实现相同的缓动效果，不知道是哪里出问题了，求助知道的大佬指点下，谢谢了！
     */


    start() {
        const obj = { y: 0 }
        const jumpHeight = 3;

        const tween1 = tween(obj).to(2, { y: jumpHeight }, {
            onUpdate: (target: { y: number }, ratio) => {
                const pos = this.node.getPosition();
                pos.y = target.y;
                this.node.setPosition(pos);
            },
            easing: 'sineOut'
        });

        const tween2 = tween(obj).to(2, { y: 0 }, {
            onUpdate: (target: { y: number }, ratio) => {
                const pos = this.node.getPosition();
                pos.y = target.y;
                this.node.setPosition(pos);
            },
            easing: 'sineIn'
        });

        tween(obj).repeatForever(tween().sequence(tween1, tween2)).start();
    }

    update(deltaTime: number) {

    }


}


